package io.gitee.hchaojie.day02;

import org.junit.Assert;
import org.junit.Test;

import java.util.Arrays;

public class DemoMethod {

    public int getGcd(int number1, int number2) {
        return -1;
    }

    @Test
    public void testMax() {
        try {
            getMax();

            Assert.fail("没有抛异常。。。");
        } catch (RuntimeException e) {
        }
    }

    @Test
    public void testMax2() {
        Assert.assertEquals(1, getMax(1));
        Assert.assertEquals(20, getMax(1, 20));
    }

    /**
     * 2.	两个数字里面的最大值
     * 3.	数组是否排序
     * 4.	数组倒置（修改原数组；返回新数组两种形式）
     *  {1, 2, 3}   {3, 2, 1}
     */

    public int getMax(int... numbers) {
        // System.out.println(Arrays.toString(numbers));
        if (numbers.length == 0) {
            throw new RuntimeException("你至少得输入一个数字！");
        }

        Arrays.sort(numbers);

        return numbers[numbers.length - 1];
    }

    public int getMax2(int[] arrays) {
        return -1;
    }

//    public double getMax(double number1, double number2) {
//        return number1 > number2 ? number1 : number2;
//    }

//    public int getMax(int i1, int i2, int i3) {
//        int max = i1 > i2 ? i1 : i2;
//        max = max > i3 ? max : i3;
//
//        return max;
//    }

    public boolean isSorted(int[] arrays) {
        return false;
    }

    // 测试驱动，
    @Test
    public void testReverse() {
        int[] array = {2, 3, 4};
        int[] expected = {4, 3, 2};

        int[] array2 = {};
        int[] expected2 = {};


        Assert.assertArrayEquals(expected, reverse(array));
        Assert.assertArrayEquals(expected2, reverse(array2));
    }


    public int[] reverse(int[] array) {
        int[] result = new int[array.length];

        for (int i = 0; i < array.length; i++) {
            result[i] = array[array.length - i - 1];
        }

        return result;
    }

    public void reverse2(int[] array) {

    }

    // int[] array = {1, 2, 3, 4, 5}
    public void shuffle(int[] array) {
    }


}
